package com.heima.search.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.search.dtos.UserSearchDto;
import com.heima.search.pojos.ApAssociateWords;
import com.heima.search.service.AssociateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/v1/associate")
public class AssociateController {

    @Autowired
    private AssociateService associateService;

    /**
     * 用户搜索-关键词联想
     *
     * @param userSearchDto 用户搜索的关键字
     * @return 返回结果-关键词联想列表
     */
    @PostMapping("/search")
    public ResponseResult<List<ApAssociateWords>> search(@RequestBody UserSearchDto userSearchDto) {
        List<ApAssociateWords> associateWords = associateService.search(userSearchDto);
        return ResponseResult.okResult(associateWords);
    }
}
